package src;

public class Flight implements IFlight {
	private int numberFlight;
	private int numberSeats;
	private boolean flightnIsLate = false;
	private boolean flightIsCanceled = false;
	private int countPassen;
	private IPassenger listPassen[];
	

	public Flight(int numberSeats,int numberFlight) {
		
		listPassen = new IPassenger[numberSeats];
		this.numberSeats = numberSeats;
		this.numberFlight=numberFlight;
	}
	
	public int getNumberFlight(){
		return numberFlight;
	}

	public void markLate() {
		flightnIsLate = true;

		System.out.println("Flight " + numberFlight + " late");
	}

	public void markCanceled() {
		flightIsCanceled = true;
		System.out.println("Flight " + numberFlight + " canceled");

	}

	public void addPass(IPassenger pass) {
		if (numberSeats > 0) {
			listPassen[countPassen] = pass;
			numberSeats = numberSeats - 1;
			countPassen = countPassen + 1;
			System.out.println("Add passenger " + pass.getName()+" on flight number"+numberFlight);
		} else {
			System.out.println("Not free seats");
		}

	}

	public void removePass(String name) {
		IPassenger tempList[] = new IPassenger[listPassen.length];
		int j = 0;
		for (int i = 0; i < listPassen.length; i++) {

			if (listPassen[i] != null && !listPassen[i].getName().equals(name)) {
				tempList[j] = listPassen[i];
				j++;
			}
		}
		listPassen = tempList;
		numberSeats = numberSeats + 1;
		countPassen = countPassen - 1;
		System.out.println("Passenger " + name + " remove from flight number "+numberFlight);
	}

	public void printFlightDetails() {
		String late;
		String canceled;
		if (flightnIsLate == true) {
			late = "LATE";
		} else {
			late = "DONT LATE";
		}

		if (flightIsCanceled == true) {
			canceled = "CANCELED";
		} else {
			canceled = "DONT CANCELED";
		}

		System.out.println("Flight number" + numberFlight + " " + late + " "
				+ canceled +" "+"Free seats: " + numberSeats);
	}

}
